#ifndef CVX_DECKLINK_INPUT_CALLBACK_H
#define CVX_DECKLINK_INPUT_CALLBACK_H 1

#include "afxcmn.h"
#include "cvxImage.h"
#include "DeckLinkAPI_h.h"

class CMechAlignDlg;

//capture frames from cameras
class CvxDecklinkInputCallback : public IDeckLinkInputCallback
{

private:
	int	      m_refCount;
	CvSize    m_size;
	bool      m_binocular;
	IplImage *m_leftImage;    //left  eye luv422
	IplImage *m_rightImage;   //right eye luv422

	int m_rightFlip;            //horizontal (flip=0), vertical (flip=1) or both(flip=-1)
	int m_frameNum;
	unsigned int m_capRatio;    //1-60  30/fps

	CMechAlignDlg *m_pDialog;         //update onPaint in dialog
public:
	CvxDecklinkInputCallback();
	~CvxDecklinkInputCallback();

	void SetResoltion(int w, int h, bool bi);
	void SetUpdataDialog(CMechAlignDlg *pDialog){m_pDialog = pDialog;}
	void SetRightFlip(int flag){m_rightFlip = flag;};
	void SetFps(float fps);
	

	virtual HRESULT STDMETHODCALLTYPE	QueryInterface(REFIID iid, LPVOID *ppv);
	virtual ULONG STDMETHODCALLTYPE		AddRef(void);
	virtual ULONG STDMETHODCALLTYPE		Release(void);

	virtual HRESULT STDMETHODCALLTYPE	VideoInputFormatChanged(BMDVideoInputFormatChangedEvents notificationEvents, 
										IDeckLinkDisplayMode* newDisplayMode, BMDDetectedVideoInputFormatFlags detectedSignalFlags);
	//left eye and right image is captured  
	virtual HRESULT STDMETHODCALLTYPE	VideoInputFrameArrived(IDeckLinkVideoInputFrame* pArrivedFrame, 
										IDeckLinkAudioInputPacket*);

private:
//	void ClearImages(void);
//	void CreateImages(int w, int h);

};

void cvxYUV422toGray(int w, int h, unsigned char *pData, IplImage *grayImage);
void cvxYUV422toRGB(int w, int h, unsigned char *pData, IplImage *rgbImage, bool flipUV);

#endif